package com.nanohadoop.mapreduce.handler;

import com.nanohadoop.mapreduce.core.Mapper;
import com.nanohadoop.mapreduce.core.MapperContext;

import java.io.IOException;

/**
 * WordCount示例的Mapper实现
 */
public class WordCountMapper extends Mapper<String, String, String, Integer> {
    @Override
    public void map(String key, String value, MapperContext<String, String, String, Integer> context)
            throws IOException, InterruptedException {
        for (String word : value.split("\\s+")) {
            // Remove punctuation and convert to lowercase
            String cleanedWord = word.replaceAll("[^a-zA-Z0-9]", "").toLowerCase();
            if (!cleanedWord.isEmpty()) {
                context.write(cleanedWord, 1);
            }
        }
    }
}